home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
tlx_hype.zip
/
HYPE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-05-27
|
44KB
|
1,439 lines
{.PW132}
{.HE HYPE.PAS Page # }
{$R+,V-}
PROGRAM HyperText ;
(* Copyright 1987 - Knowledge Garden Inc.
473A Malden Bridge Rd.
R.D. 2
Nassau, NY 12123 *)
(* This program implements the hypertext technique described in the
AI apprentice column in August 1987 issue of AI Expert Magazine.
This program has been tested using Turbo ver 3.01A on an IBM PC/AT and
two PC clones. It has been run under both DOS 3.2 and Concurrent 5.0 .
We would be pleased to hear your comments, good or bad, or any applications
and modifications of the program. Contact us at:
AI Expert
Miller Freeman Publications
500 Howard Street
San Francisco, CA 94105
or on the AI Expert BBS. Our id is BillandBev Thompson ,[76703,4324].
You can also contact us on BIX, our id is bbt.
Bill and Bev Thompson *)
CONST
color_base = $B800 ; (* Location of PC color screen memory map *)
mono_base = $B000 ; (* Location of PC mono screen memory map *)
esc = #27 ; (* These rest of these constants could have been defined in *)
F10 = #68 ; (* process_file, but we put them here for convenience *)
left_arrow = #75 ;
right_arrow = #77 ;
PgUp = #73 ;
PgDn = #81 ;
mark_char = '\' ;
enter = #13 ;
def_window_size_x = 65 ;
def_window_size_y = 12 ;
def_fore_color = white ;
def_back_color = red ;
TYPE
counter = 0 .. maxint ;
text_file = text[2048] ;
string255 = string[255] ;
string80 = string[80] ;
char_ptr = ^char ;
col_pos = 1 .. 80 ; (* The PC screen is 80 by 25 *)
row_pos = 1 .. 25 ;
color = 0 .. 31 ;
window_pos = RECORD (* cursor location on screen *)
x : col_pos ;
y : row_pos ;
END ;
window_ptr = ^window_desc ;
window_desc = RECORD (* Basic window description *)
next_window : window_ptr ; (* windows are linked lists of *)
prev_window : window_ptr ; (* these descriptors *)
abs_org : window_pos ; (* origin relative to upper left *)
window_size : window_pos ; (* rows and columns in window *)
cursor_pos : window_pos ; (* saves current cursor location *)
has_frame : boolean ; (* size and org do not include frame *)
fore_color : color ;
back_color : color ;
scrn_area : char_ptr ; (* pointer to actual window data *)
END ;
string_ptr = ^string255 ; (* we don't actually allocate space for 255 chars *)
line_ptr = ^line_desc ;
line_desc = RECORD (* text is stored as a linked list *)
next_line : line_ptr ;
prev_line : line_ptr ;
txt : string_ptr ; (* points to actual text data *)
END ;
mark_ptr = ^mark_desc ;
mark_desc = RECORD (* marked text is also a linked list *)
next_mark : mark_ptr ;
prev_mark : mark_ptr ;
mark_pos : window_pos ; (* location of start of mark in window *)
mark_text : string_ptr ; (* actual marked text *)
END ;
dos_rec = RECORD (* used for low-level functions *)
CASE boolean OF
true : (ax,bx,cx,dx,bp,si,di,ds,es,flags : integer) ;
false : (al,ah,bl,bh,cl,ch,dl,dh : byte) ;
END ;
monitor_type = (color_monitor,mono_monitor,ega_monitor) ;
VAR
window_list,main_window,message_window,last_window : window_ptr ;
screen_base : char_ptr ;
monitor_kind : monitor_type ;
main_file : text_file ;
button_fore,button_back : color ;
(* Important variables:
window_list - points to a linked list of window descriptors,
the top window is the currently active window.
To write in a window, bring it to the front of the list.
last_window - points to end of window list
main_window - the big window, that text initially appears in
message_window - 2 line area at the bottom of the screen, available keys,
commands etc. appear here
screen_base - points to actual memory location of screen, either
mono_base or color_base
main_file - the original text file, the one we start the program with
button_fore,
button_back - the button is the large cursor which moves from mark to mark
on a color screen it is yellow on black, on a mono screen
the text is underlined. *)
(* Note - In most cases this program uses the Turbo standard string
functions. You can probably get better performance by turning
off range checking and accessing the strings directly, but
we didn't want to make this program even less portable than it
already is. *)
(* \\\\\\\\\\\\\ Basic Utility Routines \\\\\\\\\\\\\\\\\\\\\\ *)
FUNCTION min(x,y : integer) : integer ;
BEGIN
IF x <= y
THEN min := x
ELSE min := y ;
END ; (* min *)
FUNCTION max(x,y : integer) : integer ;
BEGIN
IF x >= y
THEN max := x
ELSE max := y ;
END ; (* max *)
PROCEDURE makestr(VAR s : string255 ; len : byte) ;
(* Fixes string "s" to length "len" - pads with blanks if necessary. *)
VAR
old_length : byte ;
BEGIN
old_length := length(s) ;
(*$R- *)
s[0] := chr(len) ;
(*$R+ *)
IF old_length < len
THEN fillchar(s[old_length+1],len - old_length,' ') ;
END ; (* makestr *)
FUNCTION toupper(s : string255) : string255 ;
(* converts a string to uppercase *)
VAR
i : byte ;
BEGIN
IF length(s) > 0
THEN
FOR i := 1 TO length(s) DO
s[i] := upcase(s[i]) ;
toupper := s ;
END ; (* toupper *)
PROCEDURE strip_leading_blanks(VAR s : string255) ;
(* Trim the leading blanks from a string *)
BEGIN
IF length(s) > 0
THEN
IF s[1] = ' '
THEN
BEGIN
delete(s,1,1) ;
strip_leading_blanks(s) ;
END ;
END ; (* strip_leading_blanks *)
PROCEDURE strip_trailing_blanks(VAR s : string255) ;
(* Trim the trailing blanks from a string *)
BEGIN
IF length(s) > 0
THEN
IF s[length(s)] = ' '
THEN
BEGIN
delete(s,length(s),1) ;
strip_trailing_blanks(s) ;
END ;
END ; (* strip_trailing_blanks *)
FUNCTION tointeger(s : string255) : integer ;
(* converts a string to an integer. Returns 0 for non-numeric strings *)
VAR
num : real ;
code : integer ;
BEGIN
strip_trailing_blanks(s) ;
strip_leading_blanks(s) ;
val(s,num,code) ;
IF code = 0
THEN
IF (num < -32768.0) OR (num > 32767.0)
THEN tointeger := 0
ELSE tointeger := trunc(num)
ELSE tointeger := 0 ;
END ; (* tointeger *)
FUNCTION open(VAR f : text_file ; f_name : string80) : boolean ;
(* Open a text file and return true if file can be opened *)
BEGIN
assign(f,f_name) ;
(*$I- *)
reset(f) ;
(*$I+ *)
open := (ioresult = 0) ;
END ; (* open *)
(* \\\\\\\\\\\\\\\\\\\ Window Routines \\\\\\\\\\\\\\\\\\\\ *)
PROCEDURE draw_frame(x1,y1,x2,y2 : counter ; title : string80 ;
frame_color : color) ;
(* Draw a frame on the screen at absolute screen positions *)
(* x1,y1 - upper left corner *)
(* x2,y2 - lower right corner *)
CONST
bar = #196 ;
vert_bar = #179 ;
upper_lf = #218 ;
upper_rt = #191 ;
lower_lf = #192 ;
lower_rt = #217 ;
VAR
i : 1 .. 25 ;
border : string80 ;
PROCEDURE get_frame_co_ords ;
BEGIN
x1 := min(max(1,x1),78) ;
y1 := min(max(1,y1),23) ;
x2 := min(max(3,x2),80) ;
y2 := min(max(3,y2),25) ;
END ; (* get_frame_co_ords *)
PROCEDURE write_title ;
BEGIN
IF length(title) > (x2 - x1 - 1)
THEN title :=